import dash
from dash import html, dcc
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd

csv_file = "data.csv"
# 读取CSV数据
df = pd.read_csv(csv_file)
print(df.head())

# 创建Dash应用
app = dash.Dash(__name__)

# 定义布局
app.layout = html.Div(
    [
        html.H1("选择显示的数据"),
        dcc.RadioItems(
            id="id_radio_mode",
            options=[
                {"label": "min", "value": "min"},
                {"label": "max", "value": "max"},
                {"label": "std", "value": "std"},
            ],
            value="std",
        ),
        dcc.Graph(
            id="id_figure_source",
            style={"height": "600px"},
        ),
    ]
)


# 定义回调函数
@app.callback(Output("id_figure_source", "figure"), Input("id_radio_mode", "value"))
def update_figure(show_mode):
    print("选择查看模式:",show_mode)
    fig = px.line(df, x="time", y=show_mode, color="name")
    return fig


if __name__ == "__main__":
    app.run(debug=True, port=8090)
